<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title>terminal_interface-curses-terminfo.adb</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
*.comment {
	color: green;
}
*.symbol {
	color: red;
}
</style>
</head>
<body>
<hr><div style="text-align:center"><h1> File : terminal_interface-curses-terminfo.adb </h1></div><hr>
<pre>
<span class="comment"><em>------------------------------------------------------------------------------</em></span>
<span class="comment"><em>--                                                                          --</em></span>
<span class="comment"><em>--                           <strong>GNAT</strong> ncurses Binding                           --</em></span>
<span class="comment"><em>--                                                                          --</em></span>
<span class="comment"><em>--                    Terminal_Interface.Curses.Terminfo                    --</em></span>
<span class="comment"><em>--                                                                          --</em></span>
<span class="comment"><em>--                                 B O D Y                                  --</em></span>
<span class="comment"><em>--                                                                          --</em></span>
<span class="comment"><em>------------------------------------------------------------------------------</em></span>
<span class="comment"><em>-- Copyright 2020 Thomas E. Dickey                                          --</em></span>
<span class="comment"><em>-- Copyright 2000-2006,2009 Free Software Foundation, Inc.                  --</em></span>
<span class="comment"><em>--                                                                          --</em></span>
<span class="comment"><em>-- Permission is hereby granted, free of charge, to any person obtaining a  --</em></span>
<span class="comment"><em>-- copy of this software and associated documentation files (the            --</em></span>
<span class="comment"><em>-- "Software"), to deal in the Software without restriction, including      --</em></span>
<span class="comment"><em>-- without limitation the rights to use, copy, modify, merge, publish,      --</em></span>
<span class="comment"><em>-- distribute, distribute with modifications, sublicense, and/or sell       --</em></span>
<span class="comment"><em>-- copies of the Software, and to permit persons to whom the Software is    --</em></span>
<span class="comment"><em>-- furnished to do so, subject to the following conditions:                 --</em></span>
<span class="comment"><em>--                                                                          --</em></span>
<span class="comment"><em>-- The above copyright notice and this permission notice shall be included  --</em></span>
<span class="comment"><em>-- in all copies or substantial portions of the Software.                   --</em></span>
<span class="comment"><em>--                                                                          --</em></span>
<span class="comment"><em>-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  --</em></span>
<span class="comment"><em>-- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               --</em></span>
<span class="comment"><em>-- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   --</em></span>
<span class="comment"><em>-- IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   --</em></span>
<span class="comment"><em>-- DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    --</em></span>
<span class="comment"><em>-- OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    --</em></span>
<span class="comment"><em>-- THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               --</em></span>
<span class="comment"><em>--                                                                          --</em></span>
<span class="comment"><em>-- Except as contained in this notice, the name(s) of the above copyright   --</em></span>
<span class="comment"><em>-- holders shall not be used in advertising or otherwise to promote the     --</em></span>
<span class="comment"><em>-- sale, use or other dealings in this Software without prior written       --</em></span>
<span class="comment"><em>-- authorization.                                                           --</em></span>
<span class="comment"><em>------------------------------------------------------------------------------</em></span>
<span class="comment"><em>--  Author:  Juergen Pfeifer, 1996</em></span>
<span class="comment"><em>--  Version Control:</em></span>
<span class="comment"><em>--  @Revision: 1.7 @</em></span>
<span class="comment"><em>--  @Date: 2020/02/02 23:34:34 @</em></span>
<span class="comment"><em>--  Binding Version 01.00</em></span>
<span class="comment"><em>------------------------------------------------------------------------------</em></span>

<b>with</b> <a href="terminal_interface__ads.htm#ref_43_9">Terminal_Interface</a>.<a href="terminal_interface-curses__ads.htm#ref_48_28">Curses</a>.<a href="terminal_interface-curses-aux__ads.htm#ref_46_35">Aux</a>; <b>use</b> <a href="terminal_interface__ads.htm#ref_43_9">Terminal_Interface</a>.<a href="terminal_interface-curses__ads.htm#ref_48_28">Curses</a>.<a href="terminal_interface-curses-aux__ads.htm#ref_46_35">Aux</a>;
<b>with</b> <a href="interfac__ads.htm#ref_38_9">Interfaces</a>.C; <b>use</b> <a href="interfac__ads.htm#ref_38_9">Interfaces</a>.C;
<b>with</b> <a href="interfac__ads.htm#ref_38_9">Interfaces</a>.C.Strings; <b>use</b> <a href="interfac__ads.htm#ref_38_9">Interfaces</a>.C.Strings;
<b>with</b> Ada.Unchecked_Conversion;

<b>package</b> <b>body</b> <a href="terminal_interface__ads.htm#ref_43_9">Terminal_Interface</a>.<a href="terminal_interface-curses__ads.htm#ref_48_28">Curses</a>.<span class="symbol"><a name="ref_49_40" href="terminal_interface-curses-terminfo__ads.htm#ref_45_35">Terminfo</a></span> <b>is</b>

   <b>function</b> <span class="symbol"><a name="ref_51_13" href="terminal_interface-curses-terminfo__adb.htm#ref_53_13">Is_MinusOne_Pointer</a></span> (<span class="symbol"><a name="ref_51_34" href="terminal_interface-curses-terminfo__adb.htm#ref_53_34">P</a></span> : chars_ptr) <b>return</b> Boolean;

   <b>function</b> <span class="symbol"><a name="ref_53_13" href="terminal_interface-curses-terminfo__adb.htm#ref_51_13">Is_MinusOne_Pointer</a></span> (<span class="symbol"><a name="ref_53_34" href="terminal_interface-curses-terminfo__adb.htm#ref_51_34">P</a></span> : chars_ptr) <b>return</b> Boolean <b>is</b>
      <b>type</b> <span class="symbol"><a name="ref_54_12">Weird_Address</a></span> <b>is</b> <b>new</b> System.Storage_Elements.Integer_Address;
      <span class="symbol"><a name="ref_55_7">Invalid_Pointer</a></span> : <b>constant</b> <a href="terminal_interface-curses-terminfo__adb.htm#ref_54_12">Weird_Address</a> := -1;
      <b>function</b> To_Weird <b>is</b> <b>new</b> Ada.Unchecked_Conversion
        (Source =&gt; chars_ptr, Target =&gt; <a href="terminal_interface-curses-terminfo__adb.htm#ref_54_12">Weird_Address</a>);
   <b>begin</b>
      <b>if</b> To_Weird (<a href="terminal_interface-curses-terminfo__adb.htm#ref_51_34">P</a>) = <a href="terminal_interface-curses-terminfo__adb.htm#ref_55_7">Invalid_Pointer</a> <b>then</b>
         <b>return</b> True;
      <b>else</b>
         <b>return</b> False;
      <b>end</b> <b>if</b>;
   <b>end</b> <a href="terminal_interface-curses-terminfo__adb.htm#ref_51_13">Is_MinusOne_Pointer</a>;
   <b>pragma</b> Inline (<a href="terminal_interface-curses-terminfo__adb.htm#ref_51_13">Is_MinusOne_Pointer</a>);

<span class="comment"><em>------------------------------------------------------------------------------</em></span>
   <b>function</b> <span class="symbol"><a name="ref_68_13" href="terminal_interface-curses-terminfo__ads.htm#ref_65_13">Get_Flag</a></span> (<span class="symbol"><a name="ref_68_23" href="terminal_interface-curses-terminfo__ads.htm#ref_65_23">Name</a></span> : String) <b>return</b> Boolean
   <b>is</b>
      <b>function</b> <span class="symbol"><a name="ref_70_16">tigetflag</a></span> (<span class="symbol"><a name="ref_70_27">id</a></span> : char_array) <b>return</b> <a href="terminal_interface-curses__ads.htm#ref_2099_9">Curses_Bool</a>;
      <b>pragma</b> Import (C, tigetflag);
      <span class="symbol"><a name="ref_72_7">Txt</a></span>    : char_array (0 .. <a href="terminal_interface-curses-terminfo__ads.htm#ref_65_23">Name</a>'Length);
      <span class="symbol"><a name="ref_73_7">Length</a></span> : size_t;
   <b>begin</b>
      To_C (<a href="terminal_interface-curses-terminfo__ads.htm#ref_65_23">Name</a>, <a href="terminal_interface-curses-terminfo__adb.htm#ref_72_7">Txt</a>, <a href="terminal_interface-curses-terminfo__adb.htm#ref_73_7">Length</a>);
      <b>if</b> <a href="terminal_interface-curses-terminfo__adb.htm#ref_70_16">tigetflag</a> (<a href="terminal_interface-curses-terminfo__adb.htm#ref_72_7">Txt</a>) = <a href="terminal_interface-curses__ads.htm#ref_2099_9">Curses_Bool</a> (<a href="terminal_interface-curses-aux__ads.htm#ref_66_4">Curses_True</a>) <b>then</b>
         <b>return</b> True;
      <b>else</b>
         <b>return</b> False;
      <b>end</b> <b>if</b>;
   <b>end</b> <a href="terminal_interface-curses-terminfo__ads.htm#ref_65_13">Get_Flag</a>;

<span class="comment"><em>------------------------------------------------------------------------------</em></span>
   <b>procedure</b> <span class="symbol"><a name="ref_84_14" href="terminal_interface-curses-terminfo__ads.htm#ref_58_14">Get_String</a></span> (<span class="symbol"><a name="ref_84_26" href="terminal_interface-curses-terminfo__ads.htm#ref_58_26">Name</a></span>   : String;
                         <span class="symbol"><a name="ref_85_26" href="terminal_interface-curses-terminfo__ads.htm#ref_59_26">Value</a></span>  : <b>out</b> Terminfo_String;
                         <span class="symbol"><a name="ref_86_26" href="terminal_interface-curses-terminfo__ads.htm#ref_60_26">Result</a></span> : <b>out</b> Boolean)
   <b>is</b>
      <b>function</b> <span class="symbol"><a name="ref_88_16">tigetstr</a></span> (<span class="symbol"><a name="ref_88_26">id</a></span> : char_array) <b>return</b> chars_ptr;
      <b>pragma</b> Import (C, tigetstr, "tigetstr");
      <span class="symbol"><a name="ref_90_7">Txt</a></span>    : char_array (0 .. <a href="terminal_interface-curses-terminfo__ads.htm#ref_58_26">Name</a>'Length);
      <span class="symbol"><a name="ref_91_7">Length</a></span> : size_t;
      <span class="symbol"><a name="ref_92_7">Txt2</a></span> : chars_ptr;
   <b>begin</b>
      To_C (<a href="terminal_interface-curses-terminfo__ads.htm#ref_58_26">Name</a>, <a href="terminal_interface-curses-terminfo__adb.htm#ref_90_7">Txt</a>, <a href="terminal_interface-curses-terminfo__adb.htm#ref_91_7">Length</a>);
      <a href="terminal_interface-curses-terminfo__adb.htm#ref_92_7">Txt2</a> := <a href="terminal_interface-curses-terminfo__adb.htm#ref_88_16">tigetstr</a> (<a href="terminal_interface-curses-terminfo__adb.htm#ref_90_7">Txt</a>);
      <b>if</b> <a href="terminal_interface-curses-terminfo__adb.htm#ref_92_7">Txt2</a> = Null_Ptr <b>then</b>
         <a href="terminal_interface-curses-terminfo__ads.htm#ref_60_26">Result</a> := False;
      <b>elsif</b> <a href="terminal_interface-curses-terminfo__adb.htm#ref_51_13">Is_MinusOne_Pointer</a> (<a href="terminal_interface-curses-terminfo__adb.htm#ref_92_7">Txt2</a>) <b>then</b>
         <b>raise</b> <a href="terminal_interface-curses__ads.htm#ref_522_4">Curses_Exception</a>;
      <b>else</b>
         <a href="terminal_interface-curses-terminfo__ads.htm#ref_59_26">Value</a>  := Terminfo_String (<a href="terminal_interface-curses-aux__ads.htm#ref_96_13">Fill_String</a> (<a href="terminal_interface-curses-terminfo__adb.htm#ref_92_7">Txt2</a>));
         <a href="terminal_interface-curses-terminfo__ads.htm#ref_60_26">Result</a> := True;
      <b>end</b> <b>if</b>;
   <b>end</b> <a href="terminal_interface-curses-terminfo__ads.htm#ref_58_14">Get_String</a>;

<span class="comment"><em>------------------------------------------------------------------------------</em></span>
   <b>function</b> <span class="symbol"><a name="ref_107_13" href="terminal_interface-curses-terminfo__ads.htm#ref_61_13">Has_String</a></span> (<span class="symbol"><a name="ref_107_25" href="terminal_interface-curses-terminfo__ads.htm#ref_61_25">Name</a></span> : String) <b>return</b> Boolean
   <b>is</b>
      <b>function</b> <span class="symbol"><a name="ref_109_16">tigetstr</a></span> (<span class="symbol"><a name="ref_109_26">id</a></span> : char_array) <b>return</b> chars_ptr;
      <b>pragma</b> Import (C, tigetstr, "tigetstr");
      <span class="symbol"><a name="ref_111_7">Txt</a></span>    : char_array (0 .. <a href="terminal_interface-curses-terminfo__ads.htm#ref_61_25">Name</a>'Length);
      <span class="symbol"><a name="ref_112_7">Length</a></span> : size_t;
      <span class="symbol"><a name="ref_113_7">Txt2</a></span> : chars_ptr;
   <b>begin</b>
      To_C (<a href="terminal_interface-curses-terminfo__ads.htm#ref_61_25">Name</a>, <a href="terminal_interface-curses-terminfo__adb.htm#ref_111_7">Txt</a>, <a href="terminal_interface-curses-terminfo__adb.htm#ref_112_7">Length</a>);
      <a href="terminal_interface-curses-terminfo__adb.htm#ref_113_7">Txt2</a> := <a href="terminal_interface-curses-terminfo__adb.htm#ref_109_16">tigetstr</a> (<a href="terminal_interface-curses-terminfo__adb.htm#ref_111_7">Txt</a>);
      <b>if</b> <a href="terminal_interface-curses-terminfo__adb.htm#ref_113_7">Txt2</a> = Null_Ptr <b>then</b>
         <b>return</b> False;
      <b>elsif</b> <a href="terminal_interface-curses-terminfo__adb.htm#ref_51_13">Is_MinusOne_Pointer</a> (<a href="terminal_interface-curses-terminfo__adb.htm#ref_113_7">Txt2</a>) <b>then</b>
         <b>raise</b> <a href="terminal_interface-curses__ads.htm#ref_522_4">Curses_Exception</a>;
      <b>else</b>
         <b>return</b> True;
      <b>end</b> <b>if</b>;
   <b>end</b> <a href="terminal_interface-curses-terminfo__ads.htm#ref_61_13">Has_String</a>;

<span class="comment"><em>------------------------------------------------------------------------------</em></span>
   <b>function</b> <span class="symbol"><a name="ref_127_13" href="terminal_interface-curses-terminfo__ads.htm#ref_69_13">Get_Number</a></span> (<span class="symbol"><a name="ref_127_25" href="terminal_interface-curses-terminfo__ads.htm#ref_69_25">Name</a></span> : String) <b>return</b> Integer <b>is</b>
      <b>function</b> <span class="symbol"><a name="ref_128_16">tigetstr</a></span> (<span class="symbol"><a name="ref_128_26">s</a></span> : char_array) <b>return</b> <a href="terminal_interface-curses-aux__ads.htm#ref_49_12">C_Int</a>;
      <b>pragma</b> Import (C, tigetstr);
      <span class="symbol"><a name="ref_130_7">Txt</a></span>    : char_array (0 .. <a href="terminal_interface-curses-terminfo__ads.htm#ref_69_25">Name</a>'Length);
      <span class="symbol"><a name="ref_131_7">Length</a></span> : size_t;
   <b>begin</b>
      To_C (<a href="terminal_interface-curses-terminfo__ads.htm#ref_69_25">Name</a>, <a href="terminal_interface-curses-terminfo__adb.htm#ref_130_7">Txt</a>, <a href="terminal_interface-curses-terminfo__adb.htm#ref_131_7">Length</a>);
      <b>return</b> Integer (<a href="terminal_interface-curses-terminfo__adb.htm#ref_128_16">tigetstr</a> (<a href="terminal_interface-curses-terminfo__adb.htm#ref_130_7">Txt</a>));
   <b>end</b> <a href="terminal_interface-curses-terminfo__ads.htm#ref_69_13">Get_Number</a>;

<span class="comment"><em>------------------------------------------------------------------------------</em></span>
   <b>procedure</b> <span class="symbol"><a name="ref_138_14" href="terminal_interface-curses-terminfo__ads.htm#ref_77_14">Put_String</a></span> (<span class="symbol"><a name="ref_138_26" href="terminal_interface-curses-terminfo__ads.htm#ref_77_26">Str</a></span>    : <a href="terminal_interface-curses-terminfo__ads.htm#ref_45_35">Terminfo_String</a>;
                         <span class="symbol"><a name="ref_139_26" href="terminal_interface-curses-terminfo__ads.htm#ref_78_26">affcnt</a></span> : Natural := 1;
                         <span class="symbol"><a name="ref_140_26" href="terminal_interface-curses-terminfo__ads.htm#ref_79_26">putc</a></span>   : <a href="terminal_interface-curses-terminfo__ads.htm#ref_72_9">putctype</a> := <b>null</b>) <b>is</b>
      <b>function</b> <span class="symbol"><a name="ref_141_16">tputs</a></span> (<span class="symbol"><a name="ref_141_23">str</a></span>    : char_array;
                      <span class="symbol"><a name="ref_142_23">affcnt</a></span> : <a href="terminal_interface-curses-aux__ads.htm#ref_49_12">C_Int</a>;
                      <span class="symbol"><a name="ref_143_23">putc</a></span>   : <a href="terminal_interface-curses-terminfo__ads.htm#ref_72_9">putctype</a>) <b>return</b> <a href="terminal_interface-curses-aux__ads.htm#ref_49_12">C_Int</a>;
      <b>function</b> <span class="symbol"><a name="ref_144_16">putp</a></span> (<span class="symbol"><a name="ref_144_22">str</a></span> : char_array) <b>return</b> <a href="terminal_interface-curses-aux__ads.htm#ref_49_12">C_Int</a>;
      <b>pragma</b> Import (C, tputs);
      <b>pragma</b> Import (C, putp);
      <span class="symbol"><a name="ref_147_7">Txt</a></span>    : char_array (0 .. <a href="terminal_interface-curses-terminfo__ads.htm#ref_77_26">Str</a>'Length);
      <span class="symbol"><a name="ref_148_7">Length</a></span> : size_t;
      <span class="symbol"><a name="ref_149_7">Err</a></span> : <a href="terminal_interface-curses-aux__ads.htm#ref_49_12">C_Int</a>;
   <b>begin</b>
      To_C (String (<a href="terminal_interface-curses-terminfo__ads.htm#ref_77_26">Str</a>), <a href="terminal_interface-curses-terminfo__adb.htm#ref_147_7">Txt</a>, <a href="terminal_interface-curses-terminfo__adb.htm#ref_148_7">Length</a>);
      <b>if</b> <a href="terminal_interface-curses-terminfo__ads.htm#ref_79_26">putc</a> = <b>null</b> <b>then</b>
         <a href="terminal_interface-curses-terminfo__adb.htm#ref_149_7">Err</a> := <a href="terminal_interface-curses-terminfo__adb.htm#ref_144_16">putp</a> (<a href="terminal_interface-curses-terminfo__adb.htm#ref_147_7">Txt</a>);
      <b>else</b>
         <a href="terminal_interface-curses-terminfo__adb.htm#ref_149_7">Err</a> := <a href="terminal_interface-curses-terminfo__adb.htm#ref_141_16">tputs</a> (<a href="terminal_interface-curses-terminfo__adb.htm#ref_147_7">Txt</a>, <a href="terminal_interface-curses-aux__ads.htm#ref_49_12">C_Int</a> (<a href="terminal_interface-curses-terminfo__ads.htm#ref_78_26">affcnt</a>), <a href="terminal_interface-curses-terminfo__ads.htm#ref_79_26">putc</a>);
      <b>end</b> <b>if</b>;
      <b>if</b> <a href="terminal_interface-curses-terminfo__adb.htm#ref_149_7">Err</a> = <a href="terminal_interface-curses-aux__ads.htm#ref_64_4">Curses_Err</a> <b>then</b>
         <b>raise</b> <a href="terminal_interface-curses__ads.htm#ref_522_4">Curses_Exception</a>;
      <b>end</b> <b>if</b>;
   <b>end</b> <a href="terminal_interface-curses-terminfo__ads.htm#ref_77_14">Put_String</a>;

<b>end</b> <a href="terminal_interface__ads.htm#ref_43_9">Terminal_Interface</a>.<a href="terminal_interface-curses__ads.htm#ref_48_28">Curses</a>.<a href="terminal_interface-curses-terminfo__ads.htm#ref_45_35">Terminfo</a>;
</pre></body></html>
